package Test.StirngTest;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class Main3 {
    public static void main(String[] args) {
        // 假设有一个学生对象的列表
        List<Student> students = Arrays.asList(
                new Student("Alice", new Class("A")),
                new Student("Bob", new Class("A")),
                new Student("Charlie", new Class("B")),
                new Student("David", new Class("B")),
                new Student("Emma", new Class("C"))
        );
        for (Student student : students) {
            System.out.println(student.getName());
        }

        System.out.println();
        System.out.println();
        System.out.println();
        System.out.println();
        System.out.println();
//        for (int i = 0; i < students.size(); i++) {
//            System.out.println(students.toString());
//        }

        // 使用Stream流对班级对象按班号进行分组，并统计每个班号的数量
//        Map<String, Long> classCounts = students.stream()
//                .map(Student::getClassObject)
//                .collect(Collectors.groupingBy(Class::getClassNumber, Collectors.counting()));
//
//        // 输出结果
//        StringBuilder s = new StringBuilder();
//        for (Map.Entry<String, Long> entry : classCounts.entrySet()) {
//            System.out.println("班号: " + entry.getKey() + ", 人数: " + entry.getValue());
//            s.append(entry.getValue()).append("*").append(entry.getKey()).append(" ");
//        }
//        s = new StringBuilder(s.substring(0, s.length() - 1));
//        System.out.println(s);

    }

    static class Student {
        private String name;
        private Class classObject;

        public Student(String name, Class classObject) {
            this.name = name;
            this.classObject = classObject;
        }

        public String getName() {
            return name;
        }

        public Class getClassObject() {
            return classObject;
        }
    }

    static class Class {
        private String classNumber;

        public Class(String classNumber) {
            this.classNumber = classNumber;
        }

        public String getClassNumber() {
            return classNumber;
        }
    }
}